// 接口地址：http://cba.itlike.com/public/index.php?s=/api/page/detail
// 请求方式：get
axios.defaults.baseURL = 'http://smart-shop.itheima.net/index.php?s=/api';




const app = new Vue({
  el: '#app',
  data: {
    swiperList: [], // 轮播数据
    navList: [], // 导航数据
    goodsList: [], // 商品数据
    adImg: '',
  },
  created() {
    this.getIndexData()
  },
  mounted() {

  },
  methods: {
    async getIndexData() {
      const res = await axios({
        url: '/page/detail',
        headers: {
          platform: 'h5'
        }
      })
      console.log(res)
      this.swiperList = res.data.data.pageData.items[1].data
      // console.log(this.swiperList)
      this.navList = res.data.data.pageData.items[3].data
      // console.log(this.navList)
      this.goodsList = res.data.data.pageData.items[6].data
      console.log(this.goodsList)
      this.adImg = res.data.data.pageData.items[4].data[0].imgUrl


      // swiper初始化代码（思考：在Vue中应该在哪里初始化）
      if (this.mySwiper) {
        this.mySwiper.destroy();
      }
      this.$nextTick(() => {
        this.mySwiper = new Swiper(".swiper", {
          speed: 1000,
          loop: true,
          autoplay: {
            disableOnInteraction: false,
            delay: 2000,
          },
          pagination: {
            el: ".swiper-pagination",
          },
          centeredSlides: true,
          observer: true, //修改swiper自己或子元素时，自动初始化swiper
          observeParents: true, //修改swiper的父元素时，自动初始化swiper
          observerUpdate: true,
        });
      })
    }
  }
})